package konggao.util.bean.converter;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.commons.beanutils.Converter;

public class URIConverter implements Converter {

  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public URI convert(Class type, Object value) {
    if (value == null || type == null || !isSupport(type))
      return null;
    try {
      return new URI(value.toString());
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException(e);
    }
  }

  @SuppressWarnings("rawtypes")
  protected boolean isSupport(Class type) {
    return URI.class.equals(type);
  }
}
